/*
 * Copyright (c) 2009 the original author or authors
 *
 * Permission is hereby granted to use, modify, and distribute this file
 * in accordance with the terms of the license agreement accompanying it.
 */

package com.robotlegs.mvcs
{
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.events.IEventDispatcher;

	import com.robotlegs.base.ContextEvent;
	import com.robotlegs.core.ICommandMap;
	import com.robotlegs.core.IInjector;
	import com.robotlegs.core.IMediatorMap;

	/**
	 * Abstract MVCS command implementation
	 */
	public class Command
	{

		[Inject]
		public var contextView : DisplayObjectContainer;

		[Inject]
		public var commandMap : ICommandMap;

		[Inject]
		public var eventDispatcher : IEventDispatcher;

		[Inject]
		public var injector : IInjector;

		[Inject]
		public var mediatorMap : IMediatorMap;

		public function Command()
		{
		}

		/**
		 * @inheritDoc
		 */
		public function execute() : void
		{
		}

		/**
		 * Dispatch helper method
		 *
		 * @param event The <code>Event</code> to dispatch on the <code>IContext</code>'s <code>IEventDispatcher</code>
		 */
		protected function dispatch(type : String, body : *) : Boolean
		{
			var event : ContextEvent = new ContextEvent(type, body);

			if (eventDispatcher.hasEventListener(type))
				return eventDispatcher.dispatchEvent(event);
			return false;
		}
	}
}